package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import Listeners.AccessConferenceListener;
import Listeners.AddConferenceListener;
import Listeners.SubmitNewPaperListener;
import Model.Conference;
import Model.ConferenceManager;

/**
 * Panel that displays the list of available conference
 * that have been added to the system.  Allows users to
 * access an exist conference to perform specific tasks
 * and also add a new conference to the system.
 * 
 * @author Paul Schultz (ps87@uw.edu)
 * @version 12/01/2012
 */
@SuppressWarnings("serial")
public class ConferenceListPanel extends JPanel
{
  /**
   * Creates ConferenceListPanel used for adding/accessing
   * conferences.
   * 
   * @param the_manager Conference Manager containing all conferences.
   * @param master_frame Reference to master frame of application.
   */
  public ConferenceListPanel(final ConferenceManager the_manager, final ConferenceWizardFrame master_frame)
  {
    super();
    setLayout(new BorderLayout());
    setPreferredSize(new Dimension(550, 600));
    setBackground(Color.WHITE);
    
    JLabel header = new JLabel("Available Conferences");
    header.setForeground(Color.BLUE);
    header.setFont(new Font("Plain", Font.BOLD, 38));
    
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    title.setBackground(Color.WHITE);
    title.add(header);
    
    JLabel instructions = new JLabel("To add a new conference," +
        " please select this button:");
    instructions.setForeground(Color.RED);
    instructions.setFont(new Font("Plain", Font.PLAIN, 16));
    
    JPanel instruct_panel = new JPanel(new FlowLayout(FlowLayout.LEADING));
    instruct_panel.setBackground(Color.WHITE);
    
    JPanel north_panel = new JPanel();
    north_panel.setLayout(new BoxLayout(north_panel, BoxLayout.Y_AXIS));
    north_panel.setBackground(Color.WHITE);
    
    JButton addConference = new JButton("Add Conference");
    addConference.addActionListener(new AddConferenceListener(the_manager, master_frame));
    
    instruct_panel.add(instructions);
    instruct_panel.add(addConference);
    
    north_panel.add(title);
    //north_panel.add(Box.createVerticalStrut(10));
    north_panel.add(instruct_panel);
    
    add(north_panel, BorderLayout.NORTH);
    
    JPanel conferences_panel = new JPanel();
    conferences_panel.setLayout(new BoxLayout(conferences_panel, BoxLayout.Y_AXIS));
    conferences_panel.setBackground(Color.WHITE);
    
    conferences_panel.add(Box.createVerticalStrut(20));
    for (Conference c : the_manager.getConferences()) 
    {
      conferences_panel.add(new ConferencePanel(c, the_manager, master_frame));
    }
    
    JScrollPane scroll_panel = new JScrollPane(conferences_panel);
    add(scroll_panel, BorderLayout.CENTER);
  }
}
